﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

using ShootSearch.Core;
using ShootSearch.FileSystem;
using ShootSearch.Parsers;
using System.Xml.Serialization;
using ShootSearch.Util.Serializers;
using System.Reflection;
using System.Xml;


namespace ShootSearch.Jobs
{
    [Serializable]
    [TypeConverter(typeof(Util.ExpandableConverter<ParserJobConfig>))]
    public class ParserJobConfig: InputOutputJobConfig, IXmlSerializable
    {
        [CategoryAttribute("Output"),
                DescriptionAttribute("Output argument, include Path & FSID")]
        public InputOutputArgument OutputArgument { get; set; }
        [CategoryAttribute("Output"),
                DescriptionAttribute("Output FileSystem")]
        public AssemblyWithConfig Output { get; set; }
        [CategoryAttribute("Parsers"),
                DescriptionAttribute("The parsers setup")]
        public AssemblyWithConfigArray Parsers { get; set; }

        public ParserJobConfig():base()
        {
            Output = new AssemblyWithConfig(typeof(STFileSystem));
            Parsers = new AssemblyWithConfigArray();
            OutputArgument = new InputOutputArgument();
        }

        public override string ToString()
        {
            return "Parser configuration";
        }

        //public  ParserJobConfig 

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return new System.Xml.Schema.XmlSchema();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            base.ReadFromXml(reader);

            if (reader.ReadToFollowing("OutputArgument"))
            {
                OutputArgument = new InputOutputArgument();
                OutputArgument.ReadXml(reader);
            }


            if (reader.ReadToFollowing("Output"))
            {
                Output = new AssemblyWithConfig();
                Output.ReadXml(reader);
            }

            if (reader.ReadToFollowing("Parsers"))
            {
                Parsers = new AssemblyWithConfigArray();
                Parsers.ReadXml(reader);
            }
          
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            base.WriteToXml(writer);

            writer.WriteStartElement("OutputArgument");
            if (OutputArgument != null) OutputArgument.WriteXml(writer);
            writer.WriteEndElement();

            writer.WriteStartElement("Output");
            if (Input != null)
                Output.WriteXml(writer);
            writer.WriteEndElement();

            writer.WriteStartElement("Parsers");
            if (Input != null)
                Parsers.WriteXml(writer);
            writer.WriteEndElement();

  

        }

        #endregion
    }
}
